﻿IF OBJECT_ID('cms_sys_Log') IS NOT NULL
BEGIN
    DROP TABLE cms_sys_Log
    PRINT '<<< DROPPED TABLE cms_sys_Log >>>'
END
GO
IF OBJECT_ID('cms_sys_ParamType') IS NOT NULL
BEGIN
    DROP TABLE cms_sys_ParamType
    PRINT '<<< DROPPED TABLE cms_sys_ParamType >>>'
END
GO
CREATE TABLE cms_sys_Log(
    LogId        int         IDENTITY(1,1),
    Type         int         DEFAULT 0 NOT NULL,
    Detail       ntext       NOT NULL,
    AddTime      datetime    DEFAULT getdate() NOT NULL,
    AddUserId    int         DEFAULT 0 NOT NULL,
    CONSTRAINT PK_dbo_cms_sys_Log PRIMARY KEY NONCLUSTERED (LogId)
)
GO
IF OBJECT_ID('cms_sys_Log') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_sys_Log >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_sys_Log >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_Log', 'column', 'LogId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_Log', 'column', 'LogId'
END
exec sys.sp_addextendedproperty 'MS_Description', 'Id', 'schema', 'dbo', 'table', 'cms_sys_Log', 'column', 'LogId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_Log', 'column', 'Type'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_Log', 'column', 'Type'
END
exec sys.sp_addextendedproperty 'MS_Description', '类型', 'schema', 'dbo', 'table', 'cms_sys_Log', 'column', 'Type'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_Log', 'column', 'Detail'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_Log', 'column', 'Detail'
END
exec sys.sp_addextendedproperty 'MS_Description', '内容', 'schema', 'dbo', 'table', 'cms_sys_Log', 'column', 'Detail'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_Log', 'column', 'AddTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_Log', 'column', 'AddTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '记录时间', 'schema', 'dbo', 'table', 'cms_sys_Log', 'column', 'AddTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_Log', 'column', 'AddUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_Log', 'column', 'AddUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '用户id', 'schema', 'dbo', 'table', 'cms_sys_Log', 'column', 'AddUserId'
GO
CREATE TABLE cms_sys_ParamType(
    ParamTypeId    int              IDENTITY(1,1),
    Name           nvarchar(200)    NULL,
    KeyWord        varchar(100)     NOT NULL,
    IsSysParam     bit              DEFAULT 0 NOT NULL,
    CONSTRAINT PK_dbo_cms_sys_ParamType PRIMARY KEY NONCLUSTERED (ParamTypeId)
)
GO
IF OBJECT_ID('cms_sys_ParamType') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_sys_ParamType >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_sys_ParamType >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_ParamType', 'column', 'ParamTypeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_ParamType', 'column', 'ParamTypeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '类型id', 'schema', 'dbo', 'table', 'cms_sys_ParamType', 'column', 'ParamTypeId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_ParamType', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_ParamType', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '类型名', 'schema', 'dbo', 'table', 'cms_sys_ParamType', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_ParamType', 'column', 'KeyWord'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_ParamType', 'column', 'KeyWord'
END
exec sys.sp_addextendedproperty 'MS_Description', 'Key标识名', 'schema', 'dbo', 'table', 'cms_sys_ParamType', 'column', 'KeyWord'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_ParamType', 'column', 'IsSysParam'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_ParamType', 'column', 'IsSysParam'
END
exec sys.sp_addextendedproperty 'MS_Description', '是否系统参数', 'schema', 'dbo', 'table', 'cms_sys_ParamType', 'column', 'IsSysParam'
GO
IF OBJECT_ID('cms_sys_PSN') IS NOT NULL
BEGIN
    DROP TABLE cms_sys_PSN
    PRINT '<<< DROPPED TABLE cms_sys_PSN >>>'
END
GO
IF OBJECT_ID('cms_sys_TimeZone') IS NOT NULL
BEGIN
    DROP TABLE cms_sys_TimeZone
    PRINT '<<< DROPPED TABLE cms_sys_TimeZone >>>'
END
GO
IF OBJECT_ID('cms_sys_WordReplace') IS NOT NULL
BEGIN
    DROP TABLE cms_sys_WordReplace
    PRINT '<<< DROPPED TABLE cms_sys_WordReplace >>>'
END
GO
CREATE TABLE cms_sys_PSN(
    psnid          int              IDENTITY(1,1),
    Name           nvarchar(200)    NULL,
    Type           int              DEFAULT 0 NOT NULL,
    Url            varchar(300)     NOT NULL,
    Root           varchar(200)     NULL,
    Description    nvarchar(500)    NOT NULL,
    AddTime        datetime         DEFAULT getdate() NOT NULL,
    Xml            xml              NULL,
    TimeZoneId     int              NOT NULL,
    CONSTRAINT PK_dbo_cms_sys_PSN PRIMARY KEY NONCLUSTERED (psnid)
)
GO
IF OBJECT_ID('cms_sys_PSN') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_sys_PSN >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_sys_PSN >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'psnid'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'psnid'
END
exec sys.sp_addextendedproperty 'MS_Description', '站点id', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'psnid'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '名称', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Type'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Type'
END
exec sys.sp_addextendedproperty 'MS_Description', '类型', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Type'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Url'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Url'
END
exec sys.sp_addextendedproperty 'MS_Description', '域名URL', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Url'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Root'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Root'
END
exec sys.sp_addextendedproperty 'MS_Description', '目录', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Root'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Description'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Description'
END
exec sys.sp_addextendedproperty 'MS_Description', '描述', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Description'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'AddTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'AddTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加时间', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'AddTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Xml'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Xml'
END
exec sys.sp_addextendedproperty 'MS_Description', 'Xml', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'Xml'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'TimeZoneId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'TimeZoneId'
END
exec sys.sp_addextendedproperty 'MS_Description', '时区id', 'schema', 'dbo', 'table', 'cms_sys_PSN', 'column', 'TimeZoneId'
GO
CREATE TABLE cms_sys_TimeZone(
    TimeZoneId    int              IDENTITY(1,1),
    Name          nvarchar(200)    NOT NULL,
    TimeLag       float            DEFAULT 0 NOT NULL,
    CONSTRAINT PK_dbo_cms_sys_TimeZone PRIMARY KEY NONCLUSTERED (TimeZoneId)
)
GO
IF OBJECT_ID('cms_sys_TimeZone') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_sys_TimeZone >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_sys_TimeZone >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_TimeZone', 'column', 'TimeZoneId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_TimeZone', 'column', 'TimeZoneId'
END
exec sys.sp_addextendedproperty 'MS_Description', '时区id', 'schema', 'dbo', 'table', 'cms_sys_TimeZone', 'column', 'TimeZoneId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_TimeZone', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_TimeZone', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '名称', 'schema', 'dbo', 'table', 'cms_sys_TimeZone', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_TimeZone', 'column', 'TimeLag'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_TimeZone', 'column', 'TimeLag'
END
exec sys.sp_addextendedproperty 'MS_Description', 'GMT时差', 'schema', 'dbo', 'table', 'cms_sys_TimeZone', 'column', 'TimeLag'
GO
CREATE TABLE cms_sys_WordReplace(
    WordReplaceId      int              IDENTITY(1,1),
    WordReplaceName    nvarchar(200)    NOT NULL,
    OldValue           nvarchar(500)    NOT NULL,
    NewValue           nvarchar(500)    NOT NULL,
    Nodeids            varchar(500)     NOT NULL,
    AddTime            datetime         DEFAULT getdate() NOT NULL,
    AddUserId          int              DEFAULT 0 NOT NULL,
    Type               int              DEFAULT 0 NOT NULL,
    CONSTRAINT PK_dbo_cms_sys_WordReplace PRIMARY KEY NONCLUSTERED (WordReplaceId)
)
GO
IF OBJECT_ID('cms_sys_WordReplace') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_sys_WordReplace >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_sys_WordReplace >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'WordReplaceId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'WordReplaceId'
END
exec sys.sp_addextendedproperty 'MS_Description', 'Id', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'WordReplaceId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'WordReplaceName'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'WordReplaceName'
END
exec sys.sp_addextendedproperty 'MS_Description', '名称', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'WordReplaceName'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'OldValue'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'OldValue'
END
exec sys.sp_addextendedproperty 'MS_Description', '待替换的文字', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'OldValue'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'NewValue'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'NewValue'
END
exec sys.sp_addextendedproperty 'MS_Description', '替换后的值', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'NewValue'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'Nodeids'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'Nodeids'
END
exec sys.sp_addextendedproperty 'MS_Description', '结点范围', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'Nodeids'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'AddTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'AddTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加时间', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'AddTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'AddUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'AddUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加者id', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'AddUserId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'Type'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'Type'
END
exec sys.sp_addextendedproperty 'MS_Description', '类型', 'schema', 'dbo', 'table', 'cms_sys_WordReplace', 'column', 'Type'
GO
ALTER TABLE cms_sys_PSN ADD CONSTRAINT Refcms_sys_TimeZone44 
    FOREIGN KEY (TimeZoneId)
    REFERENCES cms_sys_TimeZone(TimeZoneId)
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_PSN_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_PSN_Save
GO 
CREATE PROCEDURE cms_PSN_Save
@psnid    	int OUTPUT,
@Name    	nvarchar(200),
@Type    	int,
@Url    	varchar(300),
@Root    	varchar(200),
@Description    	nvarchar(500),
@AddTime    	datetime,
@Xml    	xml,
@TimeZoneId    	int
AS
IF (@psnid>0) 
BEGIN
	UPDATE cms_sys_PSN
	SET 
		[Name] = @Name,
		[Type] = @Type,
		[Url] = @Url,
		[Root] = @Root,
		[Description] = @Description,
		[AddTime] = @AddTime,
		[Xml] = @Xml,
		[TimeZoneId] = @TimeZoneId
	WHERE [psnid]=@psnid
END
ELSE
BEGIN
	INSERT INTO cms_sys_PSN([Name],[Type],[Url],[Root],[Description],[AddTime],[Xml],[TimeZoneId])
	VALUES(@Name,@Type,@Url,@Root,@Description,@AddTime,@Xml,@TimeZoneId)
	SET @psnid = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_TimeZone_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_TimeZone_Save
GO 
CREATE PROCEDURE cms_TimeZone_Save
@TimeZoneId    	int OUTPUT,
@Name    	nvarchar(200),
@TimeLag    	float
AS
IF (@TimeZoneId>0) 
BEGIN
	UPDATE cms_sys_TimeZone
	SET 
		[Name] = @Name,
		[TimeLag] = @TimeLag
	WHERE [TimeZoneId]=@TimeZoneId
END
ELSE
BEGIN
	INSERT INTO cms_sys_TimeZone([Name],[TimeLag])
	VALUES(@Name,@TimeLag)
	SET @TimeZoneId = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_WordReplace_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_WordReplace_Save
GO 
CREATE PROCEDURE cms_WordReplace_Save
@WordReplaceId    	int OUTPUT,
@WordReplaceName    	nvarchar(200),
@OldValue    	nvarchar(500),
@NewValue    	nvarchar(500),
@Nodeids    	varchar(500),
@AddTime    	datetime,
@AddUserId    	int,
@Type    	int
AS
IF (@WordReplaceId>0) 
BEGIN
	UPDATE cms_sys_WordReplace
	SET 
		[WordReplaceName] = @WordReplaceName,
		[OldValue] = @OldValue,
		[NewValue] = @NewValue,
		[Nodeids] = @Nodeids,
		[AddTime] = @AddTime,
		[AddUserId] = @AddUserId,
		[Type] = @Type
	WHERE [WordReplaceId]=@WordReplaceId
END
ELSE
BEGIN
	INSERT INTO cms_sys_WordReplace([WordReplaceName],[OldValue],[NewValue],[Nodeids],[AddTime],[AddUserId],[Type])
	VALUES(@WordReplaceName,@OldValue,@NewValue,@Nodeids,@AddTime,@AddUserId,@Type)
	SET @WordReplaceId = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_Log_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_Log_Save
GO 
CREATE PROCEDURE cms_Log_Save
@LogId    	int OUTPUT,
@Type    	int,
@Detail    	ntext,
@AddTime    	datetime,
@AddUserId    	int
AS
IF (@LogId>0) 
BEGIN
	UPDATE cms_sys_Log
	SET 
		[Type] = @Type,
		[Detail] = @Detail,
		[AddTime] = @AddTime,
		[AddUserId] = @AddUserId
	WHERE [LogId]=@LogId
END
ELSE
BEGIN
	INSERT INTO cms_sys_Log([Type],[Detail],[AddTime],[AddUserId])
	VALUES(@Type,@Detail,@AddTime,@AddUserId)
	SET @LogId = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_ParamType_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_ParamType_Save
GO 
CREATE PROCEDURE cms_ParamType_Save
@ParamTypeId    	int OUTPUT,
@Name    	nvarchar(200),
@KeyWord    	varchar(100),
@IsSysParam    	bit
AS
IF (@ParamTypeId>0) 
BEGIN
	UPDATE cms_sys_ParamType
	SET 
		[Name] = @Name,
		[KeyWord] = @KeyWord,
		[IsSysParam] = @IsSysParam
	WHERE [ParamTypeId]=@ParamTypeId
END
ELSE
BEGIN
	INSERT INTO cms_sys_ParamType([Name],[KeyWord],[IsSysParam])
	VALUES(@Name,@KeyWord,@IsSysParam)
	SET @ParamTypeId = @@IDENTITY
END
GO
IF OBJECT_ID('cms_model_FormInputLimitType') IS NOT NULL
BEGIN
    DROP TABLE cms_model_FormInputLimitType
    PRINT '<<< DROPPED TABLE cms_model_FormInputLimitType >>>'
END
GO
IF OBJECT_ID('cms_model_FormInputType') IS NOT NULL
BEGIN
    DROP TABLE cms_model_FormInputType
    PRINT '<<< DROPPED TABLE cms_model_FormInputType >>>'
END
GO
IF OBJECT_ID('cms_model_FormInputValue') IS NOT NULL
BEGIN
    DROP TABLE cms_model_FormInputValue
    PRINT '<<< DROPPED TABLE cms_model_FormInputValue >>>'
END
GO
IF OBJECT_ID('cms_model_FormInputValueType') IS NOT NULL
BEGIN
    DROP TABLE cms_model_FormInputValueType
    PRINT '<<< DROPPED TABLE cms_model_FormInputValueType >>>'
END
GO
IF OBJECT_ID('cms_model_Model') IS NOT NULL
BEGIN
    DROP TABLE cms_model_Model
    PRINT '<<< DROPPED TABLE cms_model_Model >>>'
END
GO
IF OBJECT_ID('cms_model_ModelField') IS NOT NULL
BEGIN
    DROP TABLE cms_model_ModelField
    PRINT '<<< DROPPED TABLE cms_model_ModelField >>>'
END
GO
CREATE TABLE cms_model_FormInputLimitType(
    FormInputLimitTypeId    int              IDENTITY(1,1),
    Name                    nvarchar(200)    NULL,
    RegStr                  nvarchar(500)    NULL,
    KeyWord                 varchar(100)     NOT NULL,
    CONSTRAINT PK__cms_model_FormInputLimitType PRIMARY KEY NONCLUSTERED (FormInputLimitTypeId)
)
GO
IF OBJECT_ID('cms_model_FormInputLimitType') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_model_FormInputLimitType >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_model_FormInputLimitType >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputLimitType', 'column', 'FormInputLimitTypeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputLimitType', 'column', 'FormInputLimitTypeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '限制类型ID', 'schema', 'dbo', 'table', 'cms_model_FormInputLimitType', 'column', 'FormInputLimitTypeId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputLimitType', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputLimitType', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '类型名称', 'schema', 'dbo', 'table', 'cms_model_FormInputLimitType', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputLimitType', 'column', 'RegStr'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputLimitType', 'column', 'RegStr'
END
exec sys.sp_addextendedproperty 'MS_Description', '正则规则', 'schema', 'dbo', 'table', 'cms_model_FormInputLimitType', 'column', 'RegStr'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputLimitType', 'column', 'KeyWord'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputLimitType', 'column', 'KeyWord'
END
exec sys.sp_addextendedproperty 'MS_Description', 'KeyWord', 'schema', 'dbo', 'table', 'cms_model_FormInputLimitType', 'column', 'KeyWord'
GO
CREATE TABLE cms_model_FormInputType(
    FormInputTypeId    int              IDENTITY(1,1),
    Name               nvarchar(200)    NOT NULL,
    FormItem           varchar(200)     NOT NULL,
    Description        nvarchar(500)    NULL,
    AddTime            datetime         DEFAULT getdate() NOT NULL,
    AddUserId          int              DEFAULT 0 NOT NULL,
    CONSTRAINT PK__cms_model_FormInputType PRIMARY KEY NONCLUSTERED (FormInputTypeId)
)
GO
IF OBJECT_ID('cms_model_FormInputType') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_model_FormInputType >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_model_FormInputType >>>'
GO
 
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'FormInputTypeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'FormInputTypeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '录入类型id', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'FormInputTypeId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '名称', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'FormItem'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'FormItem'
END
exec sys.sp_addextendedproperty 'MS_Description', 'form元素名', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'FormItem'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'Description'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'Description'
END
exec sys.sp_addextendedproperty 'MS_Description', '描述', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'Description'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'AddTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'AddTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加时间', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'AddTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'AddUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'AddUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加者id', 'schema', 'dbo', 'table', 'cms_model_FormInputType', 'column', 'AddUserId'
GO
CREATE TABLE cms_model_FormInputValue(
    FormInputValueId        int              IDENTITY(1,1),
    FormInputValueTypeId    int              NOT NULL,
    ParentId                int              DEFAULT 0 NULL,
    Name                    nvarchar(200)    NULL,
    Status                  int              DEFAULT 0 NULL,
    DisplayOrder            int              DEFAULT 0 NULL,
    CONSTRAINT PK__cms_model_FormInputValue PRIMARY KEY NONCLUSTERED (FormInputValueId, FormInputValueTypeId)
)
GO
IF OBJECT_ID('cms_model_FormInputValue') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_model_FormInputValue >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_model_FormInputValue >>>'
GO 
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'FormInputValueId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'FormInputValueId'
END
exec sys.sp_addextendedproperty 'MS_Description', 'Id', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'FormInputValueId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'FormInputValueTypeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'FormInputValueTypeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '录入可选值类型id', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'FormInputValueTypeId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'ParentId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'ParentId'
END
exec sys.sp_addextendedproperty 'MS_Description', '父id', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'ParentId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '名称', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'Status'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'Status'
END
exec sys.sp_addextendedproperty 'MS_Description', '状态', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'Status'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'DisplayOrder'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'DisplayOrder'
END
exec sys.sp_addextendedproperty 'MS_Description', '排序', 'schema', 'dbo', 'table', 'cms_model_FormInputValue', 'column', 'DisplayOrder'
GO 
CREATE TABLE cms_model_FormInputValueType(
    FormInputValueTypeId    int              IDENTITY(1,1),
    Name                    nvarchar(200)    NULL,
    KeyWord                 varchar(100)     NULL,
    Step                    int              DEFAULT 1 NOT NULL,
    Description             nvarchar(500)    NULL,
    AddTime                 datetime         DEFAULT getdate() NOT NULL,
    AddUserId               int              DEFAULT 0 NOT NULL,
    CONSTRAINT PK__cms_model_FormInputValueType PRIMARY KEY NONCLUSTERED (FormInputValueTypeId)
)
GO 
IF OBJECT_ID('cms_model_FormInputValueType') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_model_FormInputValueType >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_model_FormInputValueType >>>'
GO
 
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'FormInputValueTypeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'FormInputValueTypeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '录入可选值类型id', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'FormInputValueTypeId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '名称', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'KeyWord'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'KeyWord'
END
exec sys.sp_addextendedproperty 'MS_Description', 'KEY', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'KeyWord'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'Step'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'Step'
END
exec sys.sp_addextendedproperty 'MS_Description', '级数', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'Step'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'Description'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'Description'
END
exec sys.sp_addextendedproperty 'MS_Description', '描述', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'Description'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'AddTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'AddTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加时间', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'AddTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'AddUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'AddUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加者id', 'schema', 'dbo', 'table', 'cms_model_FormInputValueType', 'column', 'AddUserId'
GO
CREATE TABLE cms_model_Model(
    ModelId         int              IDENTITY(1,1),
    Name            nvarchar(200)    NULL,
    TableName       varchar(100)     NOT NULL,
    Description     nvarchar(500)    NULL,
    AddTime         datetime         DEFAULT getdate() NOT NULL,
    AddUserId       int              DEFAULT 0 NOT NULL,
    UpdateTime      datetime         DEFAULT getdate() NOT NULL,
    UpdateUserId    int              DEFAULT 0 NOT NULL,
    CONSTRAINT PK__cms_model_Model PRIMARY KEY NONCLUSTERED (ModelId)
)
GO
IF OBJECT_ID('cms_model_Model') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_model_Model >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_model_Model >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'ModelId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'ModelId'
END
exec sys.sp_addextendedproperty 'MS_Description', '模型id', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'ModelId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '名称', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'TableName'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'TableName'
END
exec sys.sp_addextendedproperty 'MS_Description', '表名', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'TableName'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'Description'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'Description'
END
exec sys.sp_addextendedproperty 'MS_Description', '描述', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'Description'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'AddTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'AddTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加时间', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'AddTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'AddUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'AddUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加者id', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'AddUserId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'UpdateTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'UpdateTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '最后修改时间', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'UpdateTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'UpdateUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'UpdateUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '最后修改人id', 'schema', 'dbo', 'table', 'cms_model_Model', 'column', 'UpdateUserId'
GO
CREATE TABLE cms_model_ModelField(
    ModelFieldId            int              IDENTITY(1,1),
    FormInputLimitTypeId    int              NULL,
    FormInputValueTypeId    int              NULL,
    ModelId                 int              DEFAULT 0 NULL,
    Name                    nvarchar(200)    NULL,
    FieldName               varchar(100)     NULL,
    IsTitleField            bit              DEFAULT 0 NOT NULL,
    IsMainField             bit              DEFAULT 0 NOT NULL,
    FieldListDisplay        bit              DEFAULT 0 NOT NULL,
    FieldTypeStr            varchar(100)     NULL,
    FieldLength             int              NULL,
    DefaultValue            nvarchar(200)    NULL,
    DisplayOrder            int              DEFAULT 0 NOT NULL,
    IsContribute            bit              DEFAULT 0 NOT NULL,
    IsSearch                bit              DEFAULT 0 NOT NULL,
    IsCollect               bit              DEFAULT 0 NOT NULL,
    IsEdit                  bit              DEFAULT 0 NOT NULL,
    FieldInputPicker        varchar(20)      NULL,
    FormInputTypeId         int              NULL,
    CONSTRAINT PK__cms_model_ModelField PRIMARY KEY NONCLUSTERED (ModelFieldId)
)
GO 
IF OBJECT_ID('cms_model_ModelField') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_model_ModelField >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_model_ModelField >>>'
GO
 
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'ModelFieldId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'ModelFieldId'
END
exec sys.sp_addextendedproperty 'MS_Description', '字段id', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'ModelFieldId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FormInputLimitTypeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FormInputLimitTypeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '限制类型ID', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FormInputLimitTypeId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FormInputValueTypeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FormInputValueTypeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '录入可选值类型id', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FormInputValueTypeId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'ModelId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'ModelId'
END
exec sys.sp_addextendedproperty 'MS_Description', '所属模型id', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'ModelId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '名称', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FieldName'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FieldName'
END
exec sys.sp_addextendedproperty 'MS_Description', '表字段名', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FieldName'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsTitleField'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsTitleField'
END
exec sys.sp_addextendedproperty 'MS_Description', '是否标题字段', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsTitleField'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsMainField'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsMainField'
END
exec sys.sp_addextendedproperty 'MS_Description', '是否主内容', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsMainField'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FieldListDisplay'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FieldListDisplay'
END
exec sys.sp_addextendedproperty 'MS_Description', '是否列表显示', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FieldListDisplay'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FieldTypeStr'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FieldTypeStr'
END
exec sys.sp_addextendedproperty 'MS_Description', '表字段类型', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FieldTypeStr'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FieldLength'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FieldLength'
END
exec sys.sp_addextendedproperty 'MS_Description', '表字段长度', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FieldLength'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'DefaultValue'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'DefaultValue'
END
exec sys.sp_addextendedproperty 'MS_Description', '表字段默认值', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'DefaultValue'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'DisplayOrder'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'DisplayOrder'
END
exec sys.sp_addextendedproperty 'MS_Description', '字段排序', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'DisplayOrder'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsContribute'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsContribute'
END
exec sys.sp_addextendedproperty 'MS_Description', '是否允许投稿', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsContribute'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsSearch'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsSearch'
END
exec sys.sp_addextendedproperty 'MS_Description', '是否允许搜索', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsSearch'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsCollect'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsCollect'
END
exec sys.sp_addextendedproperty 'MS_Description', '是否允许采集', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsCollect'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsEdit'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsEdit'
END
exec sys.sp_addextendedproperty 'MS_Description', '是否可编辑', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'IsEdit'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FieldInputPicker'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FieldInputPicker'
END
exec sys.sp_addextendedproperty 'MS_Description', '内容采集器', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FieldInputPicker'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FormInputTypeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FormInputTypeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '录入类型id', 'schema', 'dbo', 'table', 'cms_model_ModelField', 'column', 'FormInputTypeId'
GO 
ALTER TABLE cms_model_FormInputValue ADD CONSTRAINT _cms_model_FormInputValueType_cms_model_FormInputValue 
    FOREIGN KEY (FormInputValueTypeId)
    REFERENCES cms_model_FormInputValueType(FormInputValueTypeId)
GO 
ALTER TABLE cms_model_ModelField ADD CONSTRAINT _cms_model_FormInputLimitType_cms_model_ModelField 
    FOREIGN KEY (FormInputLimitTypeId)
    REFERENCES cms_model_FormInputLimitType(FormInputLimitTypeId)
GO 
ALTER TABLE cms_model_ModelField ADD CONSTRAINT _cms_model_FormInputType_cms_model_ModelField 
    FOREIGN KEY (FormInputTypeId)
    REFERENCES cms_model_FormInputType(FormInputTypeId)
GO
 
ALTER TABLE cms_model_ModelField ADD CONSTRAINT _cms_model_FormInputValueType_cms_model_ModelField 
    FOREIGN KEY (FormInputValueTypeId)
    REFERENCES cms_model_FormInputValueType(FormInputValueTypeId)
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_ModelField_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_ModelField_Save
GO 
CREATE PROCEDURE cms_ModelField_Save
@ModelFieldId    	int OUTPUT,
@FormInputTypeId    	int,
@FormInputLimitTypeId    	int,
@FormInputValueTypeId    	int,
@ModelId    	int,
@Name    	nvarchar(200),
@FieldName    	varchar(100),
@FieldTypeStr    	varchar(100),
@FieldLength    	int,
@DefaultValue    	nvarchar(200),
@DisplayOrder    	int,
@IsContribute    	bit,
@IsSearch    	bit,
@IsCollect    	bit,
@IsEdit    	bit,
@IsTitleField    	bit,
@IsMainField    	bit,
@FieldListDisplay    	bit,
@FieldInputPicker    	varchar(20)
AS
IF (@ModelFieldId>0) 
BEGIN
	UPDATE cms_model_ModelField
	SET 
		[FormInputTypeId] = @FormInputTypeId,
		[FormInputLimitTypeId] = @FormInputLimitTypeId,
		[FormInputValueTypeId] = @FormInputValueTypeId,
		[ModelId] = @ModelId,
		[Name] = @Name,
		[FieldName] = @FieldName,
		[FieldTypeStr] = @FieldTypeStr,
		[FieldLength] = @FieldLength,
		[DefaultValue] = @DefaultValue,
		[DisplayOrder] = @DisplayOrder,
		[IsContribute] = @IsContribute,
		[IsSearch] = @IsSearch,
		[IsCollect] = @IsCollect,
		[IsEdit] = @IsEdit,
		[IsTitleField] = @IsTitleField,
		[IsMainField] = @IsMainField,
		[FieldListDisplay] = @FieldListDisplay,
		[FieldInputPicker] = @FieldInputPicker
	WHERE [ModelFieldId]=@ModelFieldId
END
ELSE
BEGIN
	INSERT INTO cms_model_ModelField([FormInputTypeId],[FormInputLimitTypeId],[FormInputValueTypeId],[ModelId],[Name],[FieldName],[FieldTypeStr],[FieldLength],[DefaultValue],[DisplayOrder],[IsContribute],[IsSearch],[IsCollect],[IsEdit],[IsTitleField],[IsMainField],[FieldListDisplay],[FieldInputPicker])
	VALUES(@FormInputTypeId,@FormInputLimitTypeId,@FormInputValueTypeId,@ModelId,@Name,@FieldName,@FieldTypeStr,@FieldLength,@DefaultValue,@DisplayOrder,@IsContribute,@IsSearch,@IsCollect,@IsEdit,@IsTitleField,@IsMainField,@FieldListDisplay,@FieldInputPicker)
	SET @ModelFieldId = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_Model_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_Model_Save
GO 
CREATE PROCEDURE cms_Model_Save
@ModelId    	int OUTPUT,
@Name    	nvarchar(200),
@TableName    	varchar(100),
@Description    	nvarchar(500),
@AddTime    	datetime,
@AddUserId    	int,
@UpdateTime    	datetime,
@UpdateUserId    	int
AS
IF (@ModelId>0) 
BEGIN
	UPDATE cms_model_Model
	SET 
		[Name] = @Name,
		[TableName] = @TableName,
		[Description] = @Description,
		[AddTime] = @AddTime,
		[AddUserId] = @AddUserId,
		[UpdateTime] = @UpdateTime,
		[UpdateUserId] = @UpdateUserId
	WHERE [ModelId]=@ModelId
END
ELSE
BEGIN
	INSERT INTO cms_model_Model([Name],[TableName],[Description],[AddTime],[AddUserId],[UpdateTime],[UpdateUserId])
	VALUES(@Name,@TableName,@Description,@AddTime,@AddUserId,@UpdateTime,@UpdateUserId)
	SET @ModelId = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_FormInputLimitType_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_FormInputLimitType_Save
GO 
CREATE PROCEDURE cms_FormInputLimitType_Save
@FormInputLimitTypeId    	int OUTPUT,
@Name    	nvarchar(200),
@RegStr    	nvarchar(500),
@KeyWord    	varchar(100)
AS
IF (@FormInputLimitTypeId>0) 
BEGIN
	UPDATE cms_model_FormInputLimitType
	SET 
		[Name] = @Name,
		[RegStr] = @RegStr,
		[KeyWord] = @KeyWord
	WHERE [FormInputLimitTypeId]=@FormInputLimitTypeId
END
ELSE
BEGIN
	INSERT INTO cms_model_FormInputLimitType([Name],[RegStr],[KeyWord])
	VALUES(@Name,@RegStr,@KeyWord)
	SET @FormInputLimitTypeId = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_FormInputType_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_FormInputType_Save
GO 
CREATE PROCEDURE cms_FormInputType_Save
@FormInputTypeId    	int OUTPUT,
@Name    	nvarchar(200),
@FormItem    	varchar(200),
@Description    	nvarchar(500),
@AddTime    	datetime,
@AddUserId    	int
AS
IF (@FormInputTypeId>0) 
BEGIN
	UPDATE cms_model_FormInputType
	SET 
		[Name] = @Name,
		[FormItem] = @FormItem,
		[Description] = @Description,
		[AddTime] = @AddTime,
		[AddUserId] = @AddUserId
	WHERE [FormInputTypeId]=@FormInputTypeId
END
ELSE
BEGIN
	INSERT INTO cms_model_FormInputType([Name],[FormItem],[Description],[AddTime],[AddUserId])
	VALUES(@Name,@FormItem,@Description,@AddTime,@AddUserId)
	SET @FormInputTypeId = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_FormInputValue_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_FormInputValue_Save
GO 
CREATE PROCEDURE cms_FormInputValue_Save
@FormInputValueId    	int OUTPUT,
@FormInputValueTypeId    	int,
@ParentId    	int,
@Name    	nvarchar(200),
@Status    	int,
@DisplayOrder    	int
AS
IF (@FormInputValueId>0) 
BEGIN
	UPDATE cms_model_FormInputValue
	SET 
		[ParentId] = @ParentId,
		[Name] = @Name,
		[Status] = @Status,
		[DisplayOrder] = @DisplayOrder
	WHERE [FormInputValueId]=@FormInputValueId AND [FormInputValueTypeId]=@FormInputValueTypeId
END
ELSE
BEGIN
	INSERT INTO cms_model_FormInputValue([FormInputValueTypeId],[ParentId],[Name],[Status],[DisplayOrder])
	VALUES(@FormInputValueTypeId,@ParentId,@Name,@Status,@DisplayOrder)
    --修改排序
	update cms_model_FormInputValue set [DisplayOrder]=FormInputValueId where FormInputValueId = @@IDENTITY
	--
	SET @FormInputValueId = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_FormInputValueType_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_FormInputValueType_Save
GO 
CREATE PROCEDURE cms_FormInputValueType_Save
@FormInputValueTypeId    	int OUTPUT,
@Name    	nvarchar(200),
@KeyWord    	varchar(100),
@Step    	int,
@Description    	nvarchar(500),
@AddTime    	datetime,
@AddUserId    	int
AS
IF (@FormInputValueTypeId>0) 
BEGIN
	UPDATE cms_model_FormInputValueType
	SET 
		[Name] = @Name,
		[KeyWord] = @KeyWord,
		[Step] = @Step,
		[Description] = @Description,
		[AddTime] = @AddTime,
		[AddUserId] = @AddUserId
	WHERE [FormInputValueTypeId]=@FormInputValueTypeId
END
ELSE
BEGIN
	INSERT INTO cms_model_FormInputValueType([Name],[KeyWord],[Step],[Description],[AddTime],[AddUserId])
	VALUES(@Name,@KeyWord,@Step,@Description,@AddTime,@AddUserId)
	SET @FormInputValueTypeId = @@IDENTITY
END
GO
IF OBJECT_ID('cms_node_ContentPubType') IS NOT NULL
BEGIN
    DROP TABLE cms_node_ContentPubType
    PRINT '<<< DROPPED TABLE cms_node_ContentPubType >>>'
END
GO
IF OBJECT_ID('cms_node_Node') IS NOT NULL
BEGIN
    DROP TABLE cms_node_Node
    PRINT '<<< DROPPED TABLE cms_node_Node >>>'
END
GO
IF OBJECT_ID('cms_node_NodeAddionalPub') IS NOT NULL
BEGIN
    DROP TABLE cms_node_NodeAddionalPub
    PRINT '<<< DROPPED TABLE cms_node_NodeAddionalPub >>>'
END
GO
IF OBJECT_ID('cms_node_NodeGroup') IS NOT NULL
BEGIN
    DROP TABLE cms_node_NodeGroup
    PRINT '<<< DROPPED TABLE cms_node_NodeGroup >>>'
END
GO
IF OBJECT_ID('cms_node_NodeType') IS NOT NULL
BEGIN
    DROP TABLE cms_node_NodeType
    PRINT '<<< DROPPED TABLE cms_node_NodeType >>>'
END
GO
IF OBJECT_ID('cms_sys_ContentWorkFlow') IS NOT NULL
BEGIN
    DROP TABLE cms_sys_ContentWorkFlow
    PRINT '<<< DROPPED TABLE cms_sys_ContentWorkFlow >>>'
END
GO 
CREATE TABLE cms_node_ContentPubType(
    ContentPubTypeId    int              IDENTITY(1,1),
    Name                nvarchar(200)    NULL,
    IsStatic            bit              NULL,
    DisposeNum          int              NULL,
    CONSTRAINT PK__cms_node_ContentPubType PRIMARY KEY NONCLUSTERED (ContentPubTypeId)
)
GO
IF OBJECT_ID('cms_node_ContentPubType') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_node_ContentPubType >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_node_ContentPubType >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_ContentPubType', 'column', 'ContentPubTypeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_ContentPubType', 'column', 'ContentPubTypeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '发布模式id', 'schema', 'dbo', 'table', 'cms_node_ContentPubType', 'column', 'ContentPubTypeId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_ContentPubType', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_ContentPubType', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '名称', 'schema', 'dbo', 'table', 'cms_node_ContentPubType', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_ContentPubType', 'column', 'IsStatic'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_ContentPubType', 'column', 'IsStatic'
END
exec sys.sp_addextendedproperty 'MS_Description', '是否静态', 'schema', 'dbo', 'table', 'cms_node_ContentPubType', 'column', 'IsStatic'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_ContentPubType', 'column', 'DisposeNum'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_ContentPubType', 'column', 'DisposeNum'
END
exec sys.sp_addextendedproperty 'MS_Description', '列表前N页静态', 'schema', 'dbo', 'table', 'cms_node_ContentPubType', 'column', 'DisposeNum'
GO 
CREATE TABLE cms_node_Node(
    NodeId               int               IDENTITY(1,1),
    Editor               nvarchar(50)      NULL,
    Pager                varchar(50)       NULL,
    IndexName            varchar(250)      NULL,
    IndexPortalURL       varchar(300)      NULL,
    ContentPortalURL     varchar(300)      NULL,
    InheritNodeID        int               NULL,
    ParentId             int               DEFAULT 0 NULL,
    ModelId              int               DEFAULT 0 NULL,
    Name                 nvarchar(200)     NULL,
    KeyWord              varchar(100)      NOT NULL,
    Url                  varchar(300)      NOT NULL,
    ContentWorkFlowId    int               NOT NULL,
    NodeTypeId           int               NOT NULL,
    ContentPubTypeId     int               NOT NULL,
    IsAuoPub             bit               DEFAULT 0 NOT NULL,
    IsContribute         bit               DEFAULT 0 NOT NULL,
    IsHidde              bit               DEFAULT 0 NOT NULL,
    DisplayOrder         int               DEFAULT 0 NOT NULL,
    Detail               ntext             NOT NULL,
    IndexTemplate        varchar(300)      NOT NULL,
    ImageTemplate          varchar(300)      NOT NULL,
    DetailTemplate       varchar(300)      NOT NULL,
    SourcePSN            varchar(300)      NOT NULL,
    SourceUrl            varchar(300)      NOT NULL,
    SourceRootReg        nvarchar(500)     NOT NULL,
    HtmlPSN              varchar(300)      NOT NULL,
    HtmlUrl              varchar(300)      NOT NULL,
    HtmlRootReg          nvarchar(500)     NOT NULL,
    HtmlNameReg          nvarchar(500)     NOT NULL,
    SEOTitle             nvarchar(200)     NULL,
    SEOKey               nvarchar(200)     NULL,
    SEODescription       nvarchar(500)     NULL,
    ReadLimit            int               DEFAULT 0 NULL,
    AddTime              datetime          DEFAULT getdate() NOT NULL,
    AddUserId            int               DEFAULT 0 NOT NULL,
    UpdateUserId         int               DEFAULT 0 NOT NULL,
    UpdateTime           datetime          DEFAULT getdate() NOT NULL,
    WaterPic             varchar(300)      NOT NULL,
    IsWater              bit               DEFAULT 0 NOT NULL,
    Extcredits1          decimal(18, 0)    NULL,
    Extcredits2          decimal(18, 0)    NULL,
    Extcredits3          nvarchar(200)     NOT NULL,
    Extcredits4          nvarchar(200)     NOT NULL,
    Extcredits5          nvarchar(200)     NOT NULL,
    CONSTRAINT PK__cms_node_Node PRIMARY KEY NONCLUSTERED (NodeId)
)
GO 
IF OBJECT_ID('cms_node_Node') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_node_Node >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_node_Node >>>'
GO
 
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'NodeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'NodeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '结点id', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'NodeId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Editor'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Editor'
END
exec sys.sp_addextendedproperty 'MS_Description', '内容编辑器', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Editor'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Pager'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Pager'
END
exec sys.sp_addextendedproperty 'MS_Description', '内容分页生成器', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Pager'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IndexName'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IndexName'
END
exec sys.sp_addextendedproperty 'MS_Description', '结点首页文件名', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IndexName'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IndexPortalURL'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IndexPortalURL'
END
exec sys.sp_addextendedproperty 'MS_Description', '结点首页入', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IndexPortalURL'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ContentPortalURL'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ContentPortalURL'
END
exec sys.sp_addextendedproperty 'MS_Description', '内容页入口URL', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ContentPortalURL'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'InheritNodeID'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'InheritNodeID'
END
exec sys.sp_addextendedproperty 'MS_Description', '继承的实结点', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'InheritNodeID'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ParentId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ParentId'
END
exec sys.sp_addextendedproperty 'MS_Description', '父id', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ParentId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ModelId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ModelId'
END
exec sys.sp_addextendedproperty 'MS_Description', '模型id', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ModelId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '名称', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'KeyWord'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'KeyWord'
END
exec sys.sp_addextendedproperty 'MS_Description', 'Key', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'KeyWord'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Url'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Url'
END
exec sys.sp_addextendedproperty 'MS_Description', 'URL', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Url'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ContentWorkFlowId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ContentWorkFlowId'
END
exec sys.sp_addextendedproperty 'MS_Description', '流程id', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ContentWorkFlowId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'NodeTypeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'NodeTypeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '结点类型id', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'NodeTypeId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ContentPubTypeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ContentPubTypeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '发布模式id', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ContentPubTypeId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IsAuoPub'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IsAuoPub'
END
exec sys.sp_addextendedproperty 'MS_Description', '是否自动发布', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IsAuoPub'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IsContribute'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IsContribute'
END
exec sys.sp_addextendedproperty 'MS_Description', '是否支持投稿', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IsContribute'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IsHidde'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IsHidde'
END
exec sys.sp_addextendedproperty 'MS_Description', '是否隐藏', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IsHidde'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'DisplayOrder'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'DisplayOrder'
END
exec sys.sp_addextendedproperty 'MS_Description', '排列顺序', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'DisplayOrder'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Detail'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Detail'
END
exec sys.sp_addextendedproperty 'MS_Description', '结点内容', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Detail'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IndexTemplate'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IndexTemplate'
END
exec sys.sp_addextendedproperty 'MS_Description', '首页模板', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IndexTemplate'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ImageTemplate'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ImageTemplate'
END
exec sys.sp_addextendedproperty 'MS_Description', '列表页模板', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ImageTemplate'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'DetailTemplate'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'DetailTemplate'
END
exec sys.sp_addextendedproperty 'MS_Description', '内容页模板', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'DetailTemplate'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SourcePSN'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SourcePSN'
END
exec sys.sp_addextendedproperty 'MS_Description', '资源发布点', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SourcePSN'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SourceUrl'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SourceUrl'
END
exec sys.sp_addextendedproperty 'MS_Description', '资源发布URL', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SourceUrl'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SourceRootReg'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SourceRootReg'
END
exec sys.sp_addextendedproperty 'MS_Description', '资源发布目录规则', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SourceRootReg'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'HtmlPSN'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'HtmlPSN'
END
exec sys.sp_addextendedproperty 'MS_Description', '静态发布点(PSM)', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'HtmlPSN'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'HtmlUrl'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'HtmlUrl'
END
exec sys.sp_addextendedproperty 'MS_Description', '内容发布URL', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'HtmlUrl'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'HtmlRootReg'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'HtmlRootReg'
END
exec sys.sp_addextendedproperty 'MS_Description', '内容发布目录规则', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'HtmlRootReg'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'HtmlNameReg'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'HtmlNameReg'
END
exec sys.sp_addextendedproperty 'MS_Description', '内容页面命名规则', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'HtmlNameReg'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SEOTitle'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SEOTitle'
END
exec sys.sp_addextendedproperty 'MS_Description', 'SEOTitle', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SEOTitle'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SEOKey'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SEOKey'
END
exec sys.sp_addextendedproperty 'MS_Description', 'SEO关键字', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SEOKey'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SEODescription'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SEODescription'
END
exec sys.sp_addextendedproperty 'MS_Description', 'SEO描述', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'SEODescription'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ReadLimit'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ReadLimit'
END
exec sys.sp_addextendedproperty 'MS_Description', '阅读权限', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'ReadLimit'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'AddTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'AddTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加时间', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'AddTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'AddUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'AddUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加者id', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'AddUserId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'UpdateUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'UpdateUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '最后修改人ID', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'UpdateUserId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'UpdateTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'UpdateTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '最后修改时间', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'UpdateTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'WaterPic'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'WaterPic'
END
exec sys.sp_addextendedproperty 'MS_Description', '水印图片地址', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'WaterPic'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IsWater'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IsWater'
END
exec sys.sp_addextendedproperty 'MS_Description', '结点下图片是否水印', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'IsWater'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Extcredits1'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Extcredits1'
END
exec sys.sp_addextendedproperty 'MS_Description', '预留字段1', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Extcredits1'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Extcredits2'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Extcredits2'
END
exec sys.sp_addextendedproperty 'MS_Description', '预留字段2', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Extcredits2'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Extcredits3'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Extcredits3'
END
exec sys.sp_addextendedproperty 'MS_Description', '预留字段3', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Extcredits3'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Extcredits4'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Extcredits4'
END
exec sys.sp_addextendedproperty 'MS_Description', '预留字段4', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Extcredits4'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Extcredits5'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Extcredits5'
END
exec sys.sp_addextendedproperty 'MS_Description', '预留字段5', 'schema', 'dbo', 'table', 'cms_node_Node', 'column', 'Extcredits5'
GO
 
 
IF OBJECT_ID('cms_node_NodeAddionalPub') IS NOT NULL
BEGIN
    DROP TABLE cms_node_NodeAddionalPub
    PRINT '<<< DROPPED TABLE cms_node_NodeAddionalPub >>>'
END
GO
CREATE TABLE cms_node_NodeAddionalPub(
    NodeAddionalPubId    int              IDENTITY(1,1),
    NodeId               int              DEFAULT 0 NULL,
    Template             varchar(300)     NOT NULL,
    PubName              nvarchar(200)    NULL,
    PageName             nvarchar(200)    NULL,
    SelfPSN              varchar(300)     NOT NULL,
    SelfPSNURL           varchar(300)     NOT NULL,
    Root                 varchar(300)     NOT NULL,
    Url                  varchar(300)     NOT NULL,
    Intro                text             NULL,
    UpdateTime           datetime         DEFAULT getdate() NOT NULL,
    UpdateUserId         int              DEFAULT 0 NOT NULL,
    AddTime              datetime         DEFAULT getdate() NOT NULL,
    AddUserId            int              DEFAULT 0 NOT NULL,
    CONSTRAINT PK__cms_node_NodeAddionalPub PRIMARY KEY NONCLUSTERED (NodeAddionalPubId)
)
GO 
IF OBJECT_ID('cms_node_NodeAddionalPub') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_node_NodeAddionalPub >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_node_NodeAddionalPub >>>'
GO
 
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'NodeAddionalPubId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'NodeAddionalPubId'
END
exec sys.sp_addextendedproperty 'MS_Description', '结点附加发布id', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'NodeAddionalPubId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'NodeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'NodeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '结点id', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'NodeId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'Template'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'Template'
END
exec sys.sp_addextendedproperty 'MS_Description', '模板文件', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'Template'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'SelfPSN'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'SelfPSN'
END
exec sys.sp_addextendedproperty 'MS_Description', '自定义发布点', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'SelfPSN'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'SelfPSNURL'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'SelfPSNURL'
END
exec sys.sp_addextendedproperty 'MS_Description', '自定义发布URL', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'SelfPSNURL'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'Root'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'Root'
END
exec sys.sp_addextendedproperty 'MS_Description', '目录', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'Root'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'Url'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'Url'
END
exec sys.sp_addextendedproperty 'MS_Description', '页面地址', 'schema', 'dbo', 'table', 'cms_node_NodeAddionalPub', 'column', 'Url'
GO
CREATE TABLE cms_node_NodeGroup(
    NodeGroupId    int              IDENTITY(1,1),
    KeyWord        varchar(100)     NOT NULL,
    Name           nvarchar(200)    NULL,
    Nodeids        varchar(500)     NOT NULL,
    AddTime        datetime         DEFAULT getdate() NOT NULL,
    AddUserId      int              DEFAULT 0 NOT NULL,
    CONSTRAINT PK__cms_node_NodeGroup PRIMARY KEY NONCLUSTERED (NodeGroupId)
)
GO
IF OBJECT_ID('cms_node_NodeGroup') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_node_NodeGroup >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_node_NodeGroup >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'NodeGroupId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'NodeGroupId'
END
exec sys.sp_addextendedproperty 'MS_Description', '分组id', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'NodeGroupId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'KeyWord'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'KeyWord'
END
exec sys.sp_addextendedproperty 'MS_Description', 'Key', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'KeyWord'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '名称', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'Nodeids'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'Nodeids'
END
exec sys.sp_addextendedproperty 'MS_Description', '结点集合', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'Nodeids'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'AddTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'AddTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加时间', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'AddTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'AddUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'AddUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加者id', 'schema', 'dbo', 'table', 'cms_node_NodeGroup', 'column', 'AddUserId'
GO
CREATE TABLE cms_node_NodeType(
    NodeTypeId    int              IDENTITY(1,1),
    Name          nvarchar(200)    NULL,
    KeyWord       varchar(100)     NOT NULL,
    CONSTRAINT PK__cms_node_NodeType PRIMARY KEY NONCLUSTERED (NodeTypeId)
)
GO 
IF OBJECT_ID('cms_node_NodeType') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_node_NodeType >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_node_NodeType >>>'
GO 
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeType', 'column', 'NodeTypeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeType', 'column', 'NodeTypeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '结点类型id', 'schema', 'dbo', 'table', 'cms_node_NodeType', 'column', 'NodeTypeId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeType', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeType', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '名称', 'schema', 'dbo', 'table', 'cms_node_NodeType', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeType', 'column', 'KeyWord'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeType', 'column', 'KeyWord'
END
exec sys.sp_addextendedproperty 'MS_Description', 'Key', 'schema', 'dbo', 'table', 'cms_node_NodeType', 'column', 'KeyWord'
GO 
CREATE TABLE cms_sys_ContentWorkFlow(
    ContentWorkFlowId    int              IDENTITY(1,1),
    Name                 nvarchar(200)    NULL,
    Description          nvarchar(500)    NULL,
    CONSTRAINT PK__cms_sys_ContentWorkFlow PRIMARY KEY NONCLUSTERED (ContentWorkFlowId)
)
GO 
IF OBJECT_ID('cms_sys_ContentWorkFlow') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_sys_ContentWorkFlow >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_sys_ContentWorkFlow >>>'
GO 
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_ContentWorkFlow', 'column', 'ContentWorkFlowId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_ContentWorkFlow', 'column', 'ContentWorkFlowId'
END
exec sys.sp_addextendedproperty 'MS_Description', '流程id', 'schema', 'dbo', 'table', 'cms_sys_ContentWorkFlow', 'column', 'ContentWorkFlowId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_ContentWorkFlow', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_ContentWorkFlow', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '名称', 'schema', 'dbo', 'table', 'cms_sys_ContentWorkFlow', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_sys_ContentWorkFlow', 'column', 'Description'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_sys_ContentWorkFlow', 'column', 'Description'
END
exec sys.sp_addextendedproperty 'MS_Description', '描述', 'schema', 'dbo', 'table', 'cms_sys_ContentWorkFlow', 'column', 'Description'
GO
ALTER TABLE cms_node_Node ADD CONSTRAINT _cms_node_ContentPubType_cms_node_Node 
    FOREIGN KEY (ContentPubTypeId)
    REFERENCES cms_node_ContentPubType(ContentPubTypeId)
GO
ALTER TABLE cms_node_Node ADD CONSTRAINT _cms_node_NodeType_cms_node_Node 
    FOREIGN KEY (NodeTypeId)
    REFERENCES cms_node_NodeType(NodeTypeId)
GO
ALTER TABLE cms_node_Node ADD CONSTRAINT _cms_sys_ContentWorkFlow_cms_node_Node 
    FOREIGN KEY (ContentWorkFlowId)
    REFERENCES cms_sys_ContentWorkFlow(ContentWorkFlowId)
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_ContentPubType_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_ContentPubType_Save
GO 
CREATE PROCEDURE cms_ContentPubType_Save
@ContentPubTypeId    	int OUTPUT,
@Name    	nvarchar(200),
@IsStatic    	bit,
@DisposeNum    	int
AS
IF (@ContentPubTypeId>0) 
BEGIN
	UPDATE cms_node_ContentPubType
	SET 
		[Name] = @Name,
		[IsStatic] = @IsStatic,
		[DisposeNum] = @DisposeNum
	WHERE [ContentPubTypeId]=@ContentPubTypeId
END
ELSE
BEGIN
	INSERT INTO cms_node_ContentPubType([Name],[IsStatic],[DisposeNum])
	VALUES(@Name,@IsStatic,@DisposeNum)
	SET @ContentPubTypeId = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_Node_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_Node_Save
GO 
CREATE PROCEDURE cms_Node_Save
@NodeId    	int OUTPUT,
@Editor    	nvarchar(50),
@Pager    	varchar(50),
@IndexName    	varchar(250),
@IndexPortalURL    	varchar(300),
@ContentPortalURL    	varchar(300),
@InheritNodeID    	int,
@ParentId    	int,
@ModelId    	int,
@Name    	nvarchar(200),
@KeyWord    	varchar(100),
@Url    	varchar(300),
@ContentWorkFlowId    	int,
@NodeTypeId    	int,
@ContentPubTypeId    	int,
@IsAuoPub    	bit,
@IsContribute    	bit,
@IsHidde    	bit,
@DisplayOrder    	int,
@Detail    	ntext,
@IndexTemplate    	varchar(300),
@ImageTemplate    	varchar(300),
@DetailTemplate    	varchar(300),
@SourcePSN    	varchar(300),
@SourceUrl    	varchar(300),
@SourceRootReg    	nvarchar(500),
@HtmlPSN    	varchar(300),
@HtmlUrl    	varchar(300),
@HtmlRootReg    	nvarchar(500),
@HtmlNameReg    	nvarchar(500),
@SEOTitle    	nvarchar(200),
@SEOKey    	nvarchar(200),
@SEODescription    	nvarchar(500),
@ReadLimit    	int,
@AddTime    	datetime,
@AddUserId    	int,
@UpdateUserId    	int,
@UpdateTime    	datetime,
@WaterPic    	varchar(300),
@IsWater    	bit,
@Extcredits1    	decimal,
@Extcredits2    	decimal,
@Extcredits3    	nvarchar(200),
@Extcredits4    	nvarchar(200),
@Extcredits5    	nvarchar(200)
AS
IF (@NodeId>0) 
BEGIN
	UPDATE cms_node_Node
	SET 
		[Editor] = @Editor,
		[Pager] = @Pager,
		[IndexName] = @IndexName,
		[IndexPortalURL] = @IndexPortalURL,
		[ContentPortalURL] = @ContentPortalURL,
		[InheritNodeID] = @InheritNodeID,
		[ParentId] = @ParentId,
		[ModelId] = @ModelId,
		[Name] = @Name,
		[KeyWord] = @KeyWord,
		[Url] = @Url,
		[ContentWorkFlowId] = @ContentWorkFlowId,
		[NodeTypeId] = @NodeTypeId,
		[ContentPubTypeId] = @ContentPubTypeId,
		[IsAuoPub] = @IsAuoPub,
		[IsContribute] = @IsContribute,
		[IsHidde] = @IsHidde,
		[DisplayOrder] = @DisplayOrder,
		[Detail] = @Detail,
		[IndexTemplate] = @IndexTemplate,
		[ImageTemplate] = @ImageTemplate,
		[DetailTemplate] = @DetailTemplate,
		[SourcePSN] = @SourcePSN,
		[SourceUrl] = @SourceUrl,
		[SourceRootReg] = @SourceRootReg,
		[HtmlPSN] = @HtmlPSN,
		[HtmlUrl] = @HtmlUrl,
		[HtmlRootReg] = @HtmlRootReg,
		[HtmlNameReg] = @HtmlNameReg,
		[SEOTitle] = @SEOTitle,
		[SEOKey] = @SEOKey,
		[SEODescription] = @SEODescription,
		[ReadLimit] = @ReadLimit,
		[AddTime] = @AddTime,
		[AddUserId] = @AddUserId,
		[UpdateUserId] = @UpdateUserId,
		[UpdateTime] = @UpdateTime,
		[WaterPic] = @WaterPic,
		[IsWater] = @IsWater,
		[Extcredits1] = @Extcredits1,
		[Extcredits2] = @Extcredits2,
		[Extcredits3] = @Extcredits3,
		[Extcredits4] = @Extcredits4,
		[Extcredits5] = @Extcredits5
	WHERE [NodeId]=@NodeId
END
ELSE
BEGIN
	INSERT INTO cms_node_Node([Editor],[Pager],[IndexName],[IndexPortalURL],[ContentPortalURL],[InheritNodeID],[ParentId],[ModelId],[Name],[KeyWord],[Url],[ContentWorkFlowId],[NodeTypeId],[ContentPubTypeId],[IsAuoPub],[IsContribute],[IsHidde],[DisplayOrder],[Detail],[IndexTemplate],[ImageTemplate],[DetailTemplate],[SourcePSN],[SourceUrl],[SourceRootReg],[HtmlPSN],[HtmlUrl],[HtmlRootReg],[HtmlNameReg],[SEOTitle],[SEOKey],[SEODescription],[ReadLimit],[AddTime],[AddUserId],[UpdateUserId],[UpdateTime],[WaterPic],[IsWater],[Extcredits1],[Extcredits2],[Extcredits3],[Extcredits4],[Extcredits5])
	VALUES(@Editor,@Pager,@IndexName,@IndexPortalURL,@ContentPortalURL,@InheritNodeID,@ParentId,@ModelId,@Name,@KeyWord,@Url,@ContentWorkFlowId,@NodeTypeId,@ContentPubTypeId,@IsAuoPub,@IsContribute,@IsHidde,@DisplayOrder,@Detail,@IndexTemplate,@ImageTemplate,@DetailTemplate,@SourcePSN,@SourceUrl,@SourceRootReg,@HtmlPSN,@HtmlUrl,@HtmlRootReg,@HtmlNameReg,@SEOTitle,@SEOKey,@SEODescription,@ReadLimit,@AddTime,@AddUserId,@UpdateUserId,@UpdateTime,@WaterPic,@IsWater,@Extcredits1,@Extcredits2,@Extcredits3,@Extcredits4,@Extcredits5)
	SET @NodeId = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_NodeAddionalPub_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_NodeAddionalPub_Save
GO 
CREATE PROCEDURE cms_NodeAddionalPub_Save
@NodeAddionalPubId    	int OUTPUT,
@NodeId    	int,
@Template    	varchar(300),
@PubName    	nvarchar(200),
@PageName    	nvarchar(200),
@SelfPSN    	varchar(300),
@SelfPSNURL    	varchar(300),
@Root    	varchar(300),
@Url    	varchar(300),
@Intro    	text,
@UpdateTime    	datetime,
@UpdateUserId    	int,
@AddTime    	datetime,
@AddUserId    	int
AS
IF (@NodeAddionalPubId>0) 
BEGIN
	UPDATE cms_node_NodeAddionalPub
	SET 
		[NodeId] = @NodeId,
		[Template] = @Template,
		[PubName] = @PubName,
		[PageName] = @PageName,
		[SelfPSN] = @SelfPSN,
		[SelfPSNURL] = @SelfPSNURL,
		[Root] = @Root,
		[Url] = @Url,
		[Intro] = @Intro,
		[UpdateTime] = @UpdateTime,
		[UpdateUserId] = @UpdateUserId,
		[AddTime] = @AddTime,
		[AddUserId] = @AddUserId
	WHERE [NodeAddionalPubId]=@NodeAddionalPubId
END
ELSE
BEGIN
	INSERT INTO cms_node_NodeAddionalPub([NodeId],[Template],[PubName],[PageName],[SelfPSN],[SelfPSNURL],[Root],[Url],[Intro],[UpdateTime],[UpdateUserId],[AddTime],[AddUserId])
	VALUES(@NodeId,@Template,@PubName,@PageName,@SelfPSN,@SelfPSNURL,@Root,@Url,@Intro,@UpdateTime,@UpdateUserId,@AddTime,@AddUserId)
	SET @NodeAddionalPubId = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_NodeGroup_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_NodeGroup_Save
GO 
CREATE PROCEDURE cms_NodeGroup_Save
@NodeGroupId    	int OUTPUT,
@KeyWord    	varchar(100),
@Name    	nvarchar(200),
@Nodeids    	varchar(500),
@AddTime    	datetime,
@AddUserId    	int
AS
IF (@NodeGroupId>0) 
BEGIN
	UPDATE cms_node_NodeGroup
	SET 
		[KeyWord] = @KeyWord,
		[Name] = @Name,
		[Nodeids] = @Nodeids,
		[AddTime] = @AddTime,
		[AddUserId] = @AddUserId
	WHERE [NodeGroupId]=@NodeGroupId
END
ELSE
BEGIN
	INSERT INTO cms_node_NodeGroup([KeyWord],[Name],[Nodeids],[AddTime],[AddUserId])
	VALUES(@KeyWord,@Name,@Nodeids,@AddTime,@AddUserId)
	SET @NodeGroupId = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_NodeType_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_NodeType_Save
GO 
CREATE PROCEDURE cms_NodeType_Save
@NodeTypeId    	int OUTPUT,
@Name    	nvarchar(200),
@KeyWord    	varchar(100)
AS
IF (@NodeTypeId>0) 
BEGIN
	UPDATE cms_node_NodeType
	SET 
		[Name] = @Name,
		[KeyWord] = @KeyWord
	WHERE [NodeTypeId]=@NodeTypeId
END
ELSE
BEGIN
	INSERT INTO cms_node_NodeType([Name],[KeyWord])
	VALUES(@Name,@KeyWord)
	SET @NodeTypeId = @@IDENTITY
END
GO
IF OBJECT_ID('cms_content_Content') IS NOT NULL
BEGIN
    DROP TABLE cms_content_Content
    PRINT '<<< DROPPED TABLE cms_content_Content >>>'
END
GO
IF OBJECT_ID('cms_node_NodeContentSort') IS NOT NULL
BEGIN
    DROP TABLE cms_node_NodeContentSort
    PRINT '<<< DROPPED TABLE cms_node_NodeContentSort >>>'
END
GO
CREATE TABLE cms_content_Content(
    ContentId            int               IDENTITY(1,1),
    Status               int               DEFAULT 0 NOT NULL,
    PubStatus            int               DEFAULT 0 NOT NULL,
    NodeId               int               DEFAULT 0 NULL,
    NodeContentSortId    int               DEFAULT 0 NOT NULL,
    ExtendId             int               DEFAULT 0 NULL,
    ExtendTableName      varchar(100)      NOT NULL,
    Name                 nvarchar(200)     NULL,
    Template             varchar(300)      NOT NULL,
    SelfPSN              varchar(300)      NULL,
    SelfURL              varchar(300)      NULL,
    HtmlName             nvarchar(200)     NULL,
    Url                  varchar(300)      NOT NULL,
    ExtraUrl             varchar(300)      NULL,
    TopWeight            int               DEFAULT 0 NULL,
    EliteWeight          int               DEFAULT 0 NULL,
    DisplayOrder         int               DEFAULT 0 NOT NULL,
    PubUserId            int               DEFAULT 0 NOT NULL,
    Type                 int               DEFAULT 0 NOT NULL,
    PubTime              datetime          DEFAULT getdate() NOT NULL,
    AddUserId            int               DEFAULT 0 NOT NULL,
    AddTime              datetime          DEFAULT getdate() NOT NULL,
    UpdateUserId         int               DEFAULT 0 NOT NULL,
    UpdateTime           datetime          DEFAULT getdate() NOT NULL,
    Click                int               DEFAULT 0 NULL,
    SEOTitle             nvarchar(200)     NOT NULL,
    SEOKey               nvarchar(200)     NOT NULL,
    SEODescription       nvarchar(500)     NOT NULL,
    ReadLimit            int               DEFAULT 0 NULL,
    Extcredits1          decimal(18, 0)    NULL,
    Extcredits2          decimal(18, 0)    NULL,
    Extcredits3          nvarchar(200)     NOT NULL,
    Extcredits4          nvarchar(200)     NOT NULL,
    Extcredits5          nvarchar(200)     NOT NULL,
    CONSTRAINT PK__cms_content_Content PRIMARY KEY NONCLUSTERED (ContentId)
)
GO
IF OBJECT_ID('cms_content_Content') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_content_Content >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_content_Content >>>'
GO
 
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'ContentId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'ContentId'
END
exec sys.sp_addextendedproperty 'MS_Description', '信息id', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'ContentId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Status'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Status'
END
exec sys.sp_addextendedproperty 'MS_Description', '审核状态', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Status'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'PubStatus'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'PubStatus'
END
exec sys.sp_addextendedproperty 'MS_Description', '发布状态', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'PubStatus'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'NodeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'NodeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '结点id', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'NodeId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'ExtendId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'ExtendId'
END
exec sys.sp_addextendedproperty 'MS_Description', '扩展信息id', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'ExtendId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '标题', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Template'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Template'
END
exec sys.sp_addextendedproperty 'MS_Description', '模板', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Template'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'SelfPSN'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'SelfPSN'
END
exec sys.sp_addextendedproperty 'MS_Description', '自定义发布点(PSN):', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'SelfPSN'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'SelfURL'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'SelfURL'
END
exec sys.sp_addextendedproperty 'MS_Description', '自定义发布URL', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'SelfURL'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'HtmlName'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'HtmlName'
END
exec sys.sp_addextendedproperty 'MS_Description', '发布文件名', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'HtmlName'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Url'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Url'
END
exec sys.sp_addextendedproperty 'MS_Description', 'url地址', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Url'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'ExtraUrl'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'ExtraUrl'
END
exec sys.sp_addextendedproperty 'MS_Description', '外部链接URL', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'ExtraUrl'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'TopWeight'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'TopWeight'
END
exec sys.sp_addextendedproperty 'MS_Description', '置顶权重', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'TopWeight'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'EliteWeight'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'EliteWeight'
END
exec sys.sp_addextendedproperty 'MS_Description', '精华权重', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'EliteWeight'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'PubUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'PubUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '发布者id', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'PubUserId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'PubTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'PubTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '发布时间', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'PubTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'AddUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'AddUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加者id', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'AddUserId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'AddTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'AddTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加时间', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'AddTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'UpdateUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'UpdateUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '最后修改人ID', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'UpdateUserId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'UpdateTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'UpdateTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '最后修改时间', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'UpdateTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Click'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Click'
END
exec sys.sp_addextendedproperty 'MS_Description', '点击数', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Click'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'SEOTitle'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'SEOTitle'
END
exec sys.sp_addextendedproperty 'MS_Description', 'SEO标题', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'SEOTitle'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'SEOKey'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'SEOKey'
END
exec sys.sp_addextendedproperty 'MS_Description', 'SEO关键字', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'SEOKey'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'SEODescription'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'SEODescription'
END
exec sys.sp_addextendedproperty 'MS_Description', 'SEO描述', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'SEODescription'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'ReadLimit'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'ReadLimit'
END
exec sys.sp_addextendedproperty 'MS_Description', '阅读权限', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'ReadLimit'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Extcredits1'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Extcredits1'
END
exec sys.sp_addextendedproperty 'MS_Description', '预留字段1', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Extcredits1'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Extcredits2'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Extcredits2'
END
exec sys.sp_addextendedproperty 'MS_Description', '预留字段2', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Extcredits2'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Extcredits3'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Extcredits3'
END
exec sys.sp_addextendedproperty 'MS_Description', '预留字段3', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Extcredits3'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Extcredits4'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Extcredits4'
END
exec sys.sp_addextendedproperty 'MS_Description', '预留字段4', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Extcredits4'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Extcredits5'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Extcredits5'
END
exec sys.sp_addextendedproperty 'MS_Description', '预留字段5', 'schema', 'dbo', 'table', 'cms_content_Content', 'column', 'Extcredits5'
GO
CREATE TABLE cms_node_NodeContentSort(
    NodeContentSortId    int              IDENTITY(1,1),
    NodeId               int              DEFAULT 0 NULL,
    KeyWord              varchar(100)     NOT NULL,
    Name                 nvarchar(200)    NULL,
    Description          nvarchar(500)    NULL,
    AddTime              datetime         DEFAULT getdate() NOT NULL,
    AddUserId            int              DEFAULT 0 NOT NULL,
    CONSTRAINT PK__cms_node_NodeContentSort_1 PRIMARY KEY NONCLUSTERED (NodeContentSortId)
)
GO
IF OBJECT_ID('cms_node_NodeContentSort') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_node_NodeContentSort >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_node_NodeContentSort >>>'
GO
 
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'NodeContentSortId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'NodeContentSortId'
END
exec sys.sp_addextendedproperty 'MS_Description', '结点分类id', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'NodeContentSortId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'NodeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'NodeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '结点id', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'NodeId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'KeyWord'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'KeyWord'
END
exec sys.sp_addextendedproperty 'MS_Description', 'Key', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'KeyWord'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '名称', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'Description'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'Description'
END
exec sys.sp_addextendedproperty 'MS_Description', '描述', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'Description'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'AddTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'AddTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加时间', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'AddTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'AddUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'AddUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加人ID', 'schema', 'dbo', 'table', 'cms_node_NodeContentSort', 'column', 'AddUserId'
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_NodeContentSort_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_NodeContentSort_Save
GO 
CREATE PROCEDURE cms_NodeContentSort_Save
@NodeContentSortId    	int OUTPUT,
@NodeId    	int,
@KeyWord    	varchar(100),
@Name    	nvarchar(200),
@Description    	nvarchar(500),
@AddTime    	datetime,
@AddUserId    	int
AS
IF (@NodeContentSortId>0) 
BEGIN
	UPDATE cms_node_NodeContentSort
	SET 
		[NodeId] = @NodeId,
		[KeyWord] = @KeyWord,
		[Name] = @Name,
		[Description] = @Description,
		[AddTime] = @AddTime,
		[AddUserId] = @AddUserId
	WHERE [NodeContentSortId]=@NodeContentSortId
END
ELSE
BEGIN
	INSERT INTO cms_node_NodeContentSort([NodeId],[KeyWord],[Name],[Description],[AddTime],[AddUserId])
	VALUES(@NodeId,@KeyWord,@Name,@Description,@AddTime,@AddUserId)
	SET @NodeContentSortId = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_Content_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_Content_Save
GO 
CREATE PROCEDURE cms_Content_Save
@ContentId    	int OUTPUT,
@Status    	int,
@PubStatus    	int,
@NodeId    	int,
@NodeContentSortId    	int,
@ExtendId    	int,
@ExtendTableName    	varchar(100),
@Name    	nvarchar(200),
@Template    	varchar(300),
@HtmlName    	nvarchar(200),
@SelfPSN    	varchar(300),
@SelfURL    	varchar(300),
@Url    	varchar(300),
@ExtraUrl    	varchar(300),
@TopWeight    	int,
@DisplayOrder    	int,
@Type    	int,
@EliteWeight    	int,
@PubUserId    	int,
@PubTime    	datetime,
@AddUserId    	int,
@AddTime    	datetime,
@UpdateUserId    	int,
@UpdateTime    	datetime,
@Click    	int,
@SEOTitle    	nvarchar(200),
@SEOKey    	nvarchar(200),
@SEODescription    	nvarchar(500),
@ReadLimit    	int,
@Extcredits1    	decimal,
@Extcredits2    	decimal,
@Extcredits3    	nvarchar(200),
@Extcredits4    	nvarchar(200),
@Extcredits5    	nvarchar(200)
AS
IF (@ContentId>0) 
BEGIN
	UPDATE cms_content_Content
	SET 
		[Status] = @Status,
		[PubStatus] = @PubStatus,
		[NodeId] = @NodeId,
		[NodeContentSortId] = @NodeContentSortId,
		[ExtendId] = @ExtendId,
		[ExtendTableName] = @ExtendTableName,
		[Name] = @Name,
		[Template] = @Template,
		[HtmlName] = @HtmlName,
		[SelfPSN] = @SelfPSN,
		[SelfURL] = @SelfURL,
		[Url] = @Url,
		[ExtraUrl] = @ExtraUrl,
		[TopWeight] = @TopWeight,
		[DisplayOrder] = @DisplayOrder,
		[Type] = @Type,
		[EliteWeight] = @EliteWeight,
		[PubUserId] = @PubUserId,
		[PubTime] = @PubTime,
		[AddUserId] = @AddUserId,
		[AddTime] = @AddTime,
		[UpdateUserId] = @UpdateUserId,
		[UpdateTime] = @UpdateTime,
		[Click] = @Click,
		[SEOTitle] = @SEOTitle,
		[SEOKey] = @SEOKey,
		[SEODescription] = @SEODescription,
		[ReadLimit] = @ReadLimit,
		[Extcredits1] = @Extcredits1,
		[Extcredits2] = @Extcredits2,
		[Extcredits3] = @Extcredits3,
		[Extcredits4] = @Extcredits4,
		[Extcredits5] = @Extcredits5
	WHERE [ContentId]=@ContentId
END
ELSE
BEGIN
	INSERT INTO cms_content_Content([Status],[PubStatus],[NodeId],[NodeContentSortId],[ExtendId],[ExtendTableName],[Name],[Template],[HtmlName],[SelfPSN],[SelfURL],[Url],[ExtraUrl],[TopWeight],[DisplayOrder],[Type],[EliteWeight],[PubUserId],[PubTime],[AddUserId],[AddTime],[UpdateUserId],[UpdateTime],[Click],[SEOTitle],[SEOKey],[SEODescription],[ReadLimit],[Extcredits1],[Extcredits2],[Extcredits3],[Extcredits4],[Extcredits5])
	VALUES(@Status,@PubStatus,@NodeId,@NodeContentSortId,@ExtendId,@ExtendTableName,@Name,@Template,@HtmlName,@SelfPSN,@SelfURL,@Url,@ExtraUrl,@TopWeight,@DisplayOrder,@Type,@EliteWeight,@PubUserId,@PubTime,@AddUserId,@AddTime,@UpdateUserId,@UpdateTime,@Click,@SEOTitle,@SEOKey,@SEODescription,@ReadLimit,@Extcredits1,@Extcredits2,@Extcredits3,@Extcredits4,@Extcredits5)
	SET @ContentId = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_DataBasePager' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_DataBasePager
GO 
 
Create PROCEDURE [dbo].[cms_DataBasePager]
@TableName nvarchar(1000),                   
@ShowColumns nvarchar(1000) = '*',		      
@Condition nvarchar(1000) = '',	          
@Orderby nvarchar(200) = '',		       
@PageNumber int = 1,                       
@PageSize int = 20,                       
@RecordCount int output					  
AS
 
 
BEGIN 
 
set @Condition ='1=1 '+ rtrim(ltrim(isnull(@Condition,'')))
set @Orderby = rtrim(ltrim(isnull(@Orderby,'')))
 
Declare @FirstRow	int  
Declare @LastRow	int	 
 
SET @FirstRow	= (@PageNumber - 1) * @PageSize + 1
SET @LastRow	= (@PageNumber - 1) * @PageSize + @PageSize
 
 
Declare @RecordCountSql nvarchar(4000) 
 
if @Condition=''
	begin
	set @RecordCountSql = 'SET @RecordCount	= (select count(1) from dbo.'+@TableName+')'
	end
else
	begin	
	set @RecordCountSql = 'SET @RecordCount	= (select count(1) from dbo.'+@TableName+' where '+@Condition+')'
	end
 
exec   sp_executesql  @RecordCountSql,N'@RecordCount int output',@RecordCount output
 
Declare @TableViewSql nvarchar(4000)	
 
 
if @Condition=''
	begin
		if @Orderby=''
			begin
				set @TableViewSql = 'WITH TableView AS (select '+@ShowColumns+',ROW_NUMBER() OVER(ORDER BY newid() asc) AS RowNumber from dbo.'+@TableName+')'
			end		
		else
			begin
				set @TableViewSql = 'WITH TableView AS (select '+@ShowColumns+',ROW_NUMBER() OVER(ORDER BY '+@Orderby+') AS RowNumber from dbo.'+@TableName+')'
			end			
	end
else
	begin
		if @Orderby=''
			begin
				set @TableViewSql = 'WITH TableView AS (select '+@ShowColumns+',ROW_NUMBER() OVER(ORDER BY newid()) AS RowNumber from dbo.'+@TableName+' where '+@Condition+')'
			end		
		else
			begin
				set @TableViewSql = 'WITH TableView AS (select '+@ShowColumns+',ROW_NUMBER() OVER(ORDER BY '+@Orderby+') AS RowNumber from dbo.'+@TableName+' where '+@Condition+')'
			end			
	end
 
 
 
DECLARE @strSql nvarchar(4000)       
 
set @strSql = @TableViewSql + 'select * from TableView WHERE RowNumber BETWEEN '+cast(@FirstRow as nvarchar(50))+' AND '+cast(@LastRow as nvarchar(50)) +' ORDER BY RowNumber ASC'
execute (@strSql)
print (@strSql)
return
END  
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cms_FormInputValue_GetListTree]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[cms_FormInputValue_GetListTree]
GO
/****** Object:  StoredProcedure [dbo].[cms_FormInputValue_GetListTree]    Script Date: 10/11/2010 12:53:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create Procedure [dbo].[cms_FormInputValue_GetListTree]
@FormInputValueTypeId int,
@ParentId int,
@level int,
@Condition varchar(1000)
AS
set @level=@level+1
declare @FormInputValueId int,@TypeName varchar(500),@sql varchar(1000),@sqlcursor varchar(1000)
declare FormInputValue_cursor cursor LOCAL for  select FormInputValueId from cms_model_FormInputValue  
          where [ParentId]= @ParentId 
                 and FormInputValueTypeId =@FormInputValueTypeId 
          order by DisplayOrder asc 
OPEN  FormInputValue_cursor 
set @FormInputValueId = 0
FETCH NEXT FROM FormInputValue_cursor into @FormInputValueId
while(@@FETCH_STATUS=0)
BEGIN
	
		set @sql='select top 1  Level='+cast(@level as nvarchar(10))+',* from cms_model_FormInputValue where FormInputValueId ='+cast(@FormInputValueId as nvarchar(50))+' '+@Condition
		exec(@sql)
		exec cms_FormInputValue_GetListTree @FormInputValueTypeId, @FormInputValueId,@level,@Condition	
		FETCH NEXT FROM FormInputValue_cursor into @FormInputValueId
		
END
CLOSE FormInputValue_cursor
DEALLOCATE FormInputValue_cursor
 

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cms_Node_GetListTree]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[cms_Node_GetListTree]
GO
/****** Object:  StoredProcedure [dbo].[cms_Node_GetListTree]    Script Date: 10/11/2010 12:53:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create Procedure [dbo].[cms_Node_GetListTree]
@ParentId int,
@level int,
@Condition varchar(1000)
AS
set @level=@level+1
declare @NodeId int,@TypeName varchar(500),@sql varchar(1000)
declare NodeTree_cursor cursor LOCAL for select NodeId from cms_node_node where [ParentId]=@ParentId  Order by   DisplayOrder desc  ,nodeid asc
OPEN  NodeTree_cursor 
set @NodeId = 0
FETCH NEXT FROM NodeTree_cursor into @NodeId
while(@@FETCH_STATUS=0)
BEGIN
	
		set @sql='select top 1  Level='+cast(@level as nvarchar(10))+',NodeId,[Name],[ParentId] from cms_node_Node where NodeId ='+cast(@NodeId as nvarchar(50))+' '+@Condition +'  Order by   DisplayOrder desc  ,nodeid asc '
		exec(@sql)
		exec cms_Node_GetListTree  @NodeId,@level,@Condition	
		FETCH NEXT FROM NodeTree_cursor into @NodeId
END
CLOSE NodeTree_cursor
DEALLOCATE NodeTree_cursor